#include "libthrd.h"
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
pthread_mutex_t *verrous;
int tailleVerrous=NBVERROUS;
int lanceClientLeger(void *param, void *(*function)(void*)){
	pthread_t th;
	if (pthread_create(&th,NULL,function,param)!=0){
		perror("pthread create");
		return -1;
	}
	if (pthread_detach(th)!=0){
		perror("pthread detach");
		return -1;
	}
	return 0;
}
int supprimeClientLeger(void * code){
	pthread_exit(code);
}
void traitement(void* m,void *(*exec)(void *))
{
	pthread_t th;
	pthread_create(&th,NULL,exec,(void *)m);
	pthread_detach(th);
}
int init_verrous(){
	verrous=malloc(NBVERROUS*sizeof(pthread_mutex_t));
	int i;
	for (i=0;i<NBVERROUS;i++){
		if (pthread_mutex_init(&verrous[i],NULL)!=0){
			free(verrous);
			return -1;
		}
	}
	return 0;
}
void P (int id){
	pthread_mutex_lock(&verrous[id]);
}
void V (int id){
	pthread_mutex_unlock(&verrous[id]);
}
